package com.xinwei.leetcode.数组;
// https://leetcode-cn.com/problems/merge-sorted-array/
public class _88_合并两个有序数组 {
    // 双指针
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int p1 = 0;
        int p2 = 0;
        int i = 0;
        int[] sort = new int[m + n];
        while (p1 < m || p2 < n) {
            if (p1 == m) {
                sort[i] = nums2[p2++];
            }else if (p2 == n) {
                sort[i] = nums1[p1++];
            }else if (nums1[p1] < nums2[p2]) {
                sort[i] = nums1[p1++];
            }else {
                sort[i] = nums2[p2++];
            }
            i++;
        }
        for (int j = 0; j < m + n; j++){
            nums1[j] = sort[j];
        }
    }
}
